#include "System/LyricsSystem.h"
#include "Data/DataManage.h"
#include "Data/LyricslableLoader.h"
#include "Data/MainSceneNode.h"
#include "SimpleAudioEngine.h"


USING_NS_CC;

void LyricsSystem::runInterface()
{
 
    auto LyricsVector = static_cast<LyricslableLoader*>(DataManage::getInstance()->getEntity("lyricslable"))->GetLyricsEntityVector();

    if (_playNum >= LyricsVector->size())  return;
    ++_playTime;

    if (!_isPlay&&_playTime<LyricsVector->at(_playNum)->lyricsStratTime)  return;

    auto mainSceneNode = static_cast<MainSceneNode*>(DataManage::getInstance()->getEntity("mainSceneNode"));
    mainSceneNode->_lyricLabel->setString(LyricsVector->at(_playNum)->lyricsContent);
    ++_playNum;
}

void LyricsSystem::playBGM(const std::string & fileName)
{
    _isPlay = true;
    CocosDenshion::SimpleAudioEngine::getInstance()->stopBackgroundMusic();
    CocosDenshion::SimpleAudioEngine::getInstance()->preloadBackgroundMusic(fileName.c_str());
    CocosDenshion::SimpleAudioEngine::getInstance()->playBackgroundMusic(fileName.c_str());
}